import Vue from 'vue'
import Vuex from 'vuex'
import {getAdminInfo} from '@/api/getData'

Vue.use(Vuex)

const state = {
	adminInfo: {
		avatar: 'default.jpg'
	},
	goodInfo:{}
}

const mutations = {
	saveAdminInfo(state, adminInfo){
		state.adminInfo = adminInfo;
	},
	saveGoodInfo(state, goodInfo){
		state.goodInfo = goodInfo;
	}
}

const getters = {
	// 参数列表state指的是state数据
	getGoodInfo(state){
		return state.goodInfo;
	},
}

const actions = {
	async getAdminData({commit}){
		try{
			// const res = await getAdminInfo()
			// if (res.status == 1) {
			// 	commit('saveAdminInfo', res.data);
			// }else{
			// 	throw new Error(res.type)
			// }
		}catch(err){
			// console.log(err.message)
		}
	},
	setAdminData({commit,state}, name){
		commit('saveGoodInfo', name);
	}
}

export default new Vuex.Store({
	state,
	actions,
	mutations,
	getters
})
